package com.hsav.kcxb.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.hsav.kcxb.R;
import com.hsav.kcxb.fragment.user_center.DomainFragment;
import com.hsav.kcxb.fragment.user_center.InfoFragment;
import com.hsav.kcxb.fragment.user_center.WorkFragment;

import java.util.ArrayList;

/**
 * Created by zhao on 2017/1/8.
 */

public class UserCenterActivity extends BaseActivity {

    private ViewPager mViewPager;
    private TabLayout mTabLayout;
    private String[] mTitles = {"作品", "相册", "域名", "资料"};
    private ArrayList<Fragment> mFrgmentList = new ArrayList<>();
    private TextView mAttenTx;
    private TextView mFansTx;

    @Override
    public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
        super.onCreate(savedInstanceState, persistentState);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.aty_usercenter_layout);
        initView();
    }

    private void initView() {
        mAttenTx = (TextView)findViewById(R.id.tv_usercenter_atten);
        mAttenTx.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(UserCenterActivity.this,AttentionActivity.class);
                startActivity(intent);
            }
        });

        mFansTx = (TextView)findViewById(R.id.tx_fans_num);
        mFansTx.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(UserCenterActivity.this,FansActivity.class);
                startActivity(intent);
            }
        });

        TextView collectionTx = (TextView)findViewById(R.id.tx_collection_name);
        collectionTx.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(UserCenterActivity.this,CollectionActivity.class);
                startActivity(intent);
            }
        });

        TextView cloudTx = (TextView)findViewById(R.id.tx_cloud);
        cloudTx.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(UserCenterActivity.this,CloudListActivity.class);
                startActivity(intent);
            }
        });



        mViewPager = (ViewPager)findViewById(R.id.viewpager_user);
        mTabLayout = (TabLayout)findViewById(R.id.tablayout_user);
        WorkFragment workFragment = WorkFragment.newInstance(0);
        WorkFragment workFragment2 = WorkFragment.newInstance(0);
//        WorkFragment workFragment3 = WorkFragment.newInstance(0);
        DomainFragment domainFragment = DomainFragment.newInstance("","");
        mFrgmentList.add(workFragment);
        mFrgmentList.add(workFragment2);
        mFrgmentList.add(domainFragment);
        InfoFragment infoFragment = InfoFragment.newInstance(null,null);
        mFrgmentList.add(infoFragment);
        mViewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return mFrgmentList.get(position);
            }

            @Override
            public int getCount() {
                return mTitles.length;
            }

            @Override
            public CharSequence getPageTitle(int position) {
                return mTitles[position];
            }
        });
        mTabLayout.setupWithViewPager(mViewPager);
        mTabLayout.setTabMode(TabLayout.MODE_FIXED);

    }
}
